<html>

<head>
  <script src="//cdn.auth0.com/js/lock/11.7.2/lock.min.js"></script>
  <script src="//cdn.auth0.com/js/auth0/9.5.1/auth0.min.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <script>
    document.addEventListener("DOMContentLoaded", function () {
      lock.show();
    });
    var lock = new Auth0Lock('MSh9Q3sxUT6ZQy0xevjgv1rHVGOvgPpO', 'neo4j-sync.auth0.com');

    var userProfile = null;
    var auth0 = new auth0.WebAuth({
      domain: 'neo4j-sync.auth0.com',
      clientID: 'MSh9Q3sxUT6ZQy0xevjgv1rHVGOvgPpO',
      callbackURL: location.href,
      callbackOnLocationHash: true
    });

    function getFirebaseToken(id_token, cb) {
      var options = {
        grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
        id_token: id_token,
        api: 'firebase'
      };
      auth0.client.delegation(options, function (err, res) {
        cb(res);
      });
    }

    lock.on("hash_parsed", function (authResult) {
      if (authResult) {
        if (authResult.error) {
          window.addEventListener('message', function (event) {
            event.source.postMessage({ userData: null, type: 'auth0:delegation-token', error: authResult.error }, event.origin);
          }, false);
        }
        if (authResult.accessToken && authResult.idToken) {
          lock.getUserInfo(authResult.accessToken, function (err, userInfo) {
            if (!err) {
              lock.hide()
            }
            window.addEventListener('message', function (event) {
              getFirebaseToken(authResult.idToken, function (res) {
                var out = { userData: null, type: 'auth0:delegation-token' }
                if (res) {
                  var data = {
                    profile: userInfo,
                    data_token: res.idToken,
                    token: authResult.idToken,
                    accessToken: authResult.accessToken,
                    state: authResult.state,
                    refreshToken: authResult.refreshToken
                  }
                  out.userData = data;
                }

                event.source.postMessage(out, event.origin);
              })
            }, false);
          });
        }
      }
    });

  </script>
</head>

<body>
  <div id="spinner-wrapper">
    <div id="wrap">
      <div class="item">
        <div class="spinner1"></div>
        <p>Loading
          <span class="dot">.</span>
        </p>
      </div>
    </div>
  </div>
  <script>

  </script>
</body>

</html>